package com.kc.gb.device.controller;

import cn.hutool.core.util.ArrayUtil;
import com.google.common.collect.Maps;
import com.kc.gb.base.dto.Result;
import com.kc.gb.device.common.interfaces.IHardware;
import com.kc.gb.device.common.utils.SpringHelper;
import com.kc.gb.device.events.support.EmergencyEvent;
import com.kc.gb.device.service.HomeAdminService;
import com.kc.gb.device.tools.DeviceCodeTool;
import com.kc.gb.base.dto.DeviceType;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.swing.*;
import java.net.SocketException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/station")
public class IndexAdminController {

    @Resource
    HomeAdminService deviceAdminService;

    @Autowired(required = false)
    List<IHardware> devices;

    /**
     * 获取设备码
     * @return
     */
    @GetMapping(path = "/device/code")
    private Result<?> getDeviceCode() {
        try {
            String deviceCode = deviceAdminService.getDeviceCode();
            return Result.success(deviceCode);
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }
    }

    @GetMapping(path = "/device/stationCode")
    private Result<?> getStationCodeByDeviceCode() throws Exception {
        String deviceCode = DeviceCodeTool.getDeviceCode();
        String stationCode = deviceAdminService.getApplicationStationCode(deviceCode);
        return Result.success(stationCode);
    }

    @GetMapping(path = "/device/emergency")
    private Result<?> emergency(boolean suspend) {
        SpringHelper.getApplicationContext().publishEvent(new EmergencyEvent(suspend));
        return Result.success();
    }

}
